package example.players;

import roshambo.Player;

public class AverageJoe implements Player{

	private int[] freq;
	@Override
	public int play() {
		int max = 0;
		int bestMove = 1;
		for(int i = 1; i < freq.length; i++) {
			if(freq[i] > max) {
				max = freq[i];
				bestMove = bestAnswer(i);
			}
		}
		return bestMove;
	}
	public int bestAnswer(int move) {
		switch(move) {
		case PEDRA:
			return PAPEL;
		case PAPEL:
			return TESOURA;
		case TESOURA:
			return PEDRA;
		}
		return PEDRA;
	}

	@Override
	public void receive(int result) {
		freq[result]++;
	}

	@Override
	public void newGame(int games) {
		freq =new int[4];
	}

}
